using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static UnityEngine.EventSystems.EventTrigger;

public enum StatType
{
    maxHP,

    damage
}


public class CharacterStats : MonoBehaviour
{
    public Stat maxHP;

    public Stat damage;

    public float currentHP;

    [HideInInspector] public int maxCombo;

    public System.Action onHealthChanged;

    public bool isDead;

    protected virtual void Start()
    {
        currentHP = GetFinalMaxHP();
    }

    #region HP And Damage
    public float GetFinalMaxHP()       
    {
        return maxHP.GetValue();
    }

    /// <summary>
    /// 对目标造成伤害
    /// </summary>
    /// <param name="_targetStat"></param>
    public virtual void DoDamage(CharacterStats _targetStat)
    {
        float totalDamage = damage.GetValue();

        _targetStat.TakeDamaged(totalDamage);
    }

    public virtual void BeDamaged(float damage)
    {
        TakeDamaged(damage);
    }

    public virtual void TakeDamaged(float _damaged)
    {
        DecreaseHP(_damaged);
        //GetComponent<Character>().DamageEffect();
        //fx.StartCoroutine("FlashFX");

        if (currentHP <= 0 && !isDead)
        {
            Die();
        }
    }

    protected virtual void DecreaseHP(float _damaged) 
    {
        currentHP -= _damaged;

        if (onHealthChanged != null)
            onHealthChanged();
    }

    protected virtual void IncreaseHP(float _heal)
    {
        currentHP += _heal;

        if (onHealthChanged != null)
            onHealthChanged();
    }

    protected virtual void Die()
    {
        isDead = true;
    }
    #endregion
}

